from poco.drivers.android.uiautomation import AndroidUiautomationPoco

from basic.device.Android import Android
from airtest.core.api import *

class cardPage(Android):

    #卡名
    # card = "com.cloudbae.lovenanning:id/card_name"
    # 全部卡包：申领状态
    cardStatus="com.cloudbae.lovenanning:id/card_operation"
    content="电动车服务扫码充电 上门维修"
    @classmethod
    def clickCard(self):
        self.poco(text='生活卡包').click()
        print("点击生活卡包")
        sleep(2)



    @classmethod
    def clickMyCard1(self):
        self.poco(text='我的卡包(1)').click()

    @classmethod
    def clickMyCard2(self):
        self.poco(text='我的卡包(2)').click()

    @classmethod
    def clickAllCard(self):
        self.poco(text='全部卡包(2)').click()


    # 申领状态
    @classmethod
    def getStatus(self):
        status = self.poco(self.cardStatus)
        listStatus=[]
        for i in range(0, len(status)):
            listStatus.append(status[i].get_text())
        print(listStatus)
        r = listStatus.count("申领")
        print(r)
        return r

    # @classmethod
    # def getMyCard(self):
    #     cardName = self.poco(self.card)
    #     cardNum = len(cardName)
    #     listName = []
    #     for i in range(0, len(cardName)):
    #         listName.append(cardName[i].get_text())
    #     print(listName)
    #     return cardNum


    from time import sleep
    @classmethod
    def getMyCard(self):
        if exists(Template(r"D:\desktop\git\YBBAirTestLab\3.png")) and exists(Template(r"D:\desktop\git\YBBAirTestLab\4.png")):
            return 2
        else:
            return 0

    # @classmethod
    # def getMyCard(self):
    #     print("查找卡片")
    #     poco = AndroidUiautomationPoco()
    #     # 直接通过 content-desc 查找
    #     count = 0
    #     print("开始查找")
    #     if poco(desc="电动车服务扫码充电 上门维修").exists():
    #         count += 1
    #     if poco(desc="市民卡扫码乘车 在线充值").exists():
    #         count += 1
    #     return count






